package com.fusion.core.file.share;

import com.stendahls.util.TextUtils;

import java.io.File;
import java.io.IOException;

/**
 * @author SwethaShivakumar 
 * Project: fusion
 * Date: Mar 14, 2009
 * URL: http://fusionwiki.co.cc
 * Mail Me At: shiva@fusionproject.co.cc
 */
public class ShareBase {
    private String path;

    public ShareBase(String path) {
        try {
            path = new File(path).getCanonicalFile().getPath();
        } catch (IOException e) {
            if(T.t)T.error("Could not resolve canonical share path: "+e);
        }
        this.path = TextUtils.makeSurePathIsMultiplatform(path);
    }

    public String getPath() {
        return path;
    }

    public String toString() {
        return "ShareBase "+path;
    }

    /**
     * @return A friendly, short version of this share. Sent over the network to other users. Don't want to send full
     * pathname because is discloses security information that remote peers don't need to know. Currently this is the
     * name of the last directory in the sharebase's path.
     */
    public String getName() {
        int i = path.lastIndexOf('/');
        if (i == -1) return path;
        return path.substring(i+1);
    }
}
